package com.firexxx.study.reflection;

import com.firexxx.study.serialize.TestModel;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @description: TODO
 * @author: zhuangzhang2
 * @date: 2021-01-21 15:01
 */
public class Main {

    public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
        TestModel testModel = new TestModel();

        Class cls = TestModel.class;
        Field[] fields = cls.getDeclaredFields();
        for (Field field : fields) {
            if (field.getName().equals("name")) {
                field.setAccessible(true);
                field.set(testModel, "1");
            }
        }

        Method[] methods = cls.getDeclaredMethods();
        for (Method method : methods) {
            if (method.getName().equals("fun")) {
                method.invoke(testModel, "1");
            }
        }
    }

}
